package com.ruoyi.user.controller.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SpffUserRelations;
import com.ruoyi.system.service.ISpffUserRelationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户关系Controller
 * 
 * @author xjj
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/userApi/relations")
public class USpffUserRelationsController extends BaseController
{
    @Autowired
    private ISpffUserRelationsService spffUserRelationsService;

    /**
     * 查询用户关系列表
     */

    @GetMapping("/list")
    public TableDataInfo list(SpffUserRelations spffUserRelations)
    {
        startPage();
        List<SpffUserRelations> list = spffUserRelationsService.selectSpffUserRelationsList(spffUserRelations);
        return getDataTable(list);
    }

    /**
     * 导出用户关系列表
     */

    @Log(title = "用户关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpffUserRelations spffUserRelations)
    {
        List<SpffUserRelations> list = spffUserRelationsService.selectSpffUserRelationsList(spffUserRelations);
        ExcelUtil<SpffUserRelations> util = new ExcelUtil<SpffUserRelations>(SpffUserRelations.class);
        util.exportExcel(response, list, "用户关系数据");
    }

    /**
     * 获取用户关系详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(spffUserRelationsService.selectSpffUserRelationsById(id));
    }

    /**
     * 新增用户关系
     */

    @Log(title = "用户关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpffUserRelations spffUserRelations)
    {
        return toAjax(spffUserRelationsService.insertSpffUserRelations(spffUserRelations));
    }

    /**
     * 修改用户关系
     */

    @Log(title = "用户关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpffUserRelations spffUserRelations)
    {
        return toAjax(spffUserRelationsService.updateSpffUserRelations(spffUserRelations));
    }

    /**
     * 删除用户关系
     */
    @Log(title = "用户关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(spffUserRelationsService.deleteSpffUserRelationsByIds(ids));
    }
}
